Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

226
Vistas
How can I update the "Important" field, which is stored in a subcollection?

How can I update the "Important" field, which is stored in a subcollection?

See image to understand better

import firebaseApp from "../../utils/firebase";
import { getFirestore, doc, updateDoc } from "firebase/firestore";
const firestoreDB = getFirestore(firebaseApp);
const USER_DATA = "UsersData";
const TASKS = "Tasks";

const updateImportantValue = async (userID, newValue) => {
  try {
    const docRef = doc(
      firestoreDB,
      USER_DATA,
      userID,
      TASKS,
      "EyS9R8dHV3EU3WS2PeQo"
    );

    await updateDoc(docRef, {
      important: newValue,
    });

    console.log(firestoreDB);
    console.log(USER_DATA);
    console.log(userID);
    console.log(TASKS);
    console.log(newValue);

    console.log("updateImportantValue - success");
  } catch (error) {
    console.log(error);
  }
};

I tried this way but it throws me an error:

TypeError: n.indexOf is not a function

at Function.fromString (index.esm2017.js:1084:1)
at ia (index.esm2017.js:16166:1)
at updateImportantValue (updateImportantValue.js:9:1)
at removeImportant (useTask.js:76:1)
at importantButton (TaskData.js:16:1)
at onClick (TaskData.js:37:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
at invokeGuardedCallback (react-dom.development.js:4056:1)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070:1)

Update

Update, I was not receiving the User ID correctly. I corrected the error and the console indicates that everything was correct, but in firestore the document does not undergo any change, the "important" field remains the same.

console.log

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda